/**
 * 
 */
package com.gmail.hh.flickrj.sample.android.tasks;

import java.util.HashSet;
import java.util.Set;

import android.os.AsyncTask;

import com.gmail.hh.flickrj.sample.android.FlickrHelper;
import com.gmail.hh.flickrj.sample.android.helper.Const;
import com.googlecode.flickrjandroid.Flickr;
import com.googlecode.flickrjandroid.oauth.OAuth;
import com.googlecode.flickrjandroid.oauth.OAuthToken;
import com.googlecode.flickrjandroid.people.User;
import com.googlecode.flickrjandroid.photos.PhotoList;

public class LoadPhotostreamTask extends AsyncTask<OAuth, Void, PhotoList> {

	/**
	 *  Load Photostream asynchron, invoke callback handler after loading
	 *  author: helmut
	 */

	// each Class using this Loader  must implement this interface
	IPhotostreamLoadedListener mCallbackLoaded;
	public interface IPhotostreamLoadedListener {
		public void onPhotostreamLoaded(PhotoList photolist);
	}

	private final String mUserId;

	/**
	 * @param flickrjAndroidSampleActivity
	 */
	public LoadPhotostreamTask(IPhotostreamLoadedListener callbackLoaded, String userId) {
		this.mCallbackLoaded = callbackLoaded;
		this.mUserId = userId;
	}

	/* (non-Javadoc)
	 * @see android.os.AsyncTask#doInBackground(Params[])
	 */
	@Override
	protected PhotoList doInBackground(OAuth... arg0) {
		OAuthToken token = arg0[0].getToken();
		Flickr f = FlickrHelper.getInstance().getFlickrAuthed(token.getOauthToken(), 
				token.getOauthTokenSecret());
		Set<String> extras = new HashSet<String>();
		extras.add("url_sq"); 
		extras.add("url_l"); 
		extras.add("url_t"); 
		extras.add("views"); 
		extras.add("geo"); 
		extras.add("description"); 
		User user = arg0[0].getUser();
		try {
			return f.getPeopleInterface().getPhotos(mUserId, extras, Const.PHOTOS_PER_PAGE, 1);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

	/* (non-Javadoc)
	 * @see android.os.AsyncTask#onPostExecute(java.lang.Object)
	 */
	@Override
	protected void onPostExecute(PhotoList photoList) {
		if (this.mCallbackLoaded != null ) {
			this.mCallbackLoaded.onPhotostreamLoaded(photoList);
		}
	}
	
}